layui.config({
    version: '1510164124181'
}).use(['form', 'laydate', 'laypage', 'layer', 'element'], function() {
    form = layui.form;
    layer = layui.layer;
    laydate = layui.laydate; //日期
    laypage = layui.laypage; //分页
    element = layui.element; //元素操作
    initData();
});

function onloadInfo() {
    initData();
}

function SearchInfo(){
    pageNo = 1
    initData()
}

function initData() {
    let state = $('#activitiesState').find('option:selected').val();
    $.ajax({
        url: httpurl + "/callCpilkePc",
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType: 'application/json',
        data: {
            "page": pageNo,
            "pagesize": pageRecords,
            "state":state==-1?'':state
        },
        success: function(data) {
            if (data.rtnCode == 200) {
                let dataList = data.data.list;
                totalRecords = data.data.total;
                HandleData(dataList);
            } else {
                totalRecords = 0;
                let data_list = '<tr>' +
                    '<td colspan="12" style="text-align:center;">暂无数据</td>' +
                    '</tr>';
                $("#tableInfo tbody").html(data_list);
            }
            layer.closeAll();
            pageLayPage("initData");
        }
    });
}

function HandleData(initdata) {
    let data_list = "";
    for (let i = 0; i < initdata.length; i++) {
        data_list += '<tr>' +
            '<td><input type="checkbox" data-id="' + initdata[i].id + '" name="box" class="aceChild"/></td>' +
            '<td>' + initdata[i].id + '</td>' +
            '<td>' + initdata[i].name + '</td>' +
            '<th><img width="100" src="' + visitimgurl + '/' + (initdata[i].productEntity == null ? "" : initdata[i].productEntity.headimg) + '"></th>' +
            '<td>' + (initdata[i].productEntity == null ? "" : initdata[i].productEntity.title) + '</td>' +
            '<td>' + initdata[i].starttime + '</td>' +
            '<td>' + initdata[i].endtime + '</td>' +
            '<td>' + initdata[i].num + '</td>' +
            '<td>' + initdata[i].sort + '</td>' +
            '<td>' +
            '<a  href="addCpike.html?CpikeId=' + initdata[i].id + '">编辑</a>&nbsp;&nbsp;' +
            '<a href="#" data-info="DeletedCpilke" data-id="' + initdata[i].id + '"  onclick="DeleteInfo(this)">删除</a>' +
            '</td>' +
            '</tr>';
    }
    $("#tableInfo tbody").html(data_list);
}

function search() {
    pageNo = 1;
    initData();
}